<?php
include('search_parser.php');
class home_parser
{
    //born today
    //box office
    //top 100
    //now playing
    //oscar winning
    //coming soon
    public static function get_home()
    {
        $home['born'] = array();
        $home['2013']['movies'] =   search_parser::get_search('count=5&num_votes=5000,&release_date=2013-01-01,2013-12-31&sort=user_rating,desc&title_type=feature,tv_movie,tv_special,mini_series,documentary,short');
        $home['top100']['movies'] = search_parser::get_search('count=5&groups=top_100');
        $home['playing']['movies'] =search_parser::get_search('count=5&groups=now-playing-us');
        $home['oscar']['movies'] =  search_parser::get_search('count=5&groups=oscar_winners&sort=release_date_us,desc');
        $home['bestpic']['movies'] =search_parser::get_search('count=5&groups=oscar_best_picture_winners&sort=release_date_us,desc');
        $home['golden']['movies'] = search_parser::get_search('count=5&groups=golden_globe_winners&sort=release_date_us,desc');
        $home['emmy']['movies'] =   search_parser::get_search('count=5&groups=emmy_winners&sort=release_date_us,desc');
        $home['soon']['movies'] =   search_parser::get_search('count=5&release_date='.date("Y-m-d").','.date('Y-m-d', strtotime("+30 days")).'&sort=moviemeter&title_type=feature');
		$home['popular']['movies'] =search_parser::get_search('count=5&release_date=2000-01-01,'.date('Y-m-d', strtotime("-90 days")).'&sort=moviemeter&colors=color&languages=en&num_votes=10000,&production_status=released&title_type=feature&user_rating=6.0,9.0');

		
        //more links queries
        $home['2013']['more'] =     'tpsearch=1&num_votes=5000,&release_date=2013-01-01,2013-12-31&sort=user_rating,desc&title_type=feature,tv_movie,tv_special,mini_series,documentary,short';
        $home['top100']['more'] =   'tpsearch=1&groups=top_100';
        $home['playing']['more'] =  'tpsearch=1&groups=now-playing-us';
        $home['oscar']['more'] =    'tpsearch=1&groups=oscar_winners&sort=release_date_us,desc';
        $home['bestpic']['more'] =  'tpsearch=1&groups=oscar_best_picture_winners&sort=release_date_us,desc';
        $home['golden']['more'] =   'tpsearch=1&groups=golden_globe_winners&sort=release_date_us,desc';
        $home['emmy']['more'] =     'tpsearch=1&groups=emmy_winners&sort=release_date_us,desc';
        $home['soon']['more'] =     'tpsearch=1&release_date='.date("Y-m-d", strtotime("-15 days")).','.date('Y-m-d', strtotime("+30 days")).'&sort=moviemeter&title_type=feature';
		$home['popular']['more'] =  'tpsearch=1&release_date=2000-01-01,'.date('Y-m-d', strtotime("-90 days")).'&sort=moviemeter&colors=color&languages=en&num_votes=10000,&production_status=released&title_type=feature&user_rating=6.0,9.0';

        $imdburl = "http://www.imdb.com/";

        //prepare DOMDocument
        $html = new DOMDocument();
        @$html->loadHTML(udnutil::read_url($imdburl));
        $domxpath = new DOMXPath( $html );

        $xpath['born'] = '//div[@class="born-today-item"]';

        $born = $domxpath->query($xpath['born']);
        foreach($born as $node)
        {
            $person['id'] = $domxpath->query("//div//a", $node)->item(0)->getAttribute('href');
            $person['id'] = substr($person['id'], strpos($person['id'],'nm'));
            $person['id'] = substr($person['id'], 0, strpos($person['id'],'/?'));

            $person['image'] = $domxpath->query("//img", $node)->item(0)->getAttribute('src');
            $person['name'] = $domxpath->query("//b", $node)->item(0)->nodeValue;
            $person['age'] = $domxpath->query('//div[@class="born-today-name fontsmall"]', $node)->item(0)->nodeValue;

            array_push($home['born'], $person);
        }

        $home['title'] = "Home";
        $home['keywords'] = "";
        return $home;
    }

}
?>